﻿using System;
using System.Windows.Input;
using WindowsPhoneEssentials.Commands;
using WindowsPhoneMvp.Navigation;
using WindowsPhoneMvp.Navigation.Parsing;

namespace WindowsPhoneMvp.Mocks.Navigation
{
    public class MockNavigationService : INavigationService
    {
        public MockNavigationService()
        {
            EnableJournaling = true;
        }

        public bool EnableJournaling { get; set; }

        public INavigationParser parser = new NavigationParser();

        public NavigationData NavigationResult { get; set; }

        public ICommand ByCommand<TView>(Action<NavigationData> parameterBuilder) where TView : IView
        {
            NavigationResult = new NavigationData(typeof(TView).Name);
            return new DelegateCommand(() => parameterBuilder(NavigationResult));
        }

        public ICommand ByCommand<TView>() where TView : IView
        {
            return new DelegateCommand(() => NavigationResult = new NavigationData(typeof(TView).Name));
        }

        public ICommand BackByCommand()
        {
            return new DelegateCommand(() => NavigationResult = new NavigationData("Back"));
        }

        public void ToView<TView>() where TView : IView
        {
            NavigationResult = new NavigationData(typeof (TView).Name);
        }

        public void ToView<TView>(Action<NavigationData> parameterBuilder) where TView : IView
        {
            NavigationResult = new NavigationData(typeof(TView).Name);
            parameterBuilder(NavigationResult);
        }

        public void ToView(string viewName, Action<NavigationData> parameterBuilder)
        {
            NavigationResult = new NavigationData(viewName);
            parameterBuilder(NavigationResult);
        }

        public void ToView(NavigationData navigationData)
        {
            NavigationResult = navigationData;
        }

        public void Back()
        {
            NavigationResult = new NavigationData("Back");
        }

        public void BackToView<TView>() where TView : IView
        {
            NavigationResult = new NavigationData("BackToView");
        }

        public INavigationService WithoutBack()
        {
            return new MockNavigationService() { EnableJournaling = false };
        }

        public void RemoveBackEntry()
        {
            
        }

        public void RemoveBackEntry<TView>() where TView : IView
        {
            
        }

        public Uri UriFor<TView>() where TView : IView
        {
            NavigationResult = new NavigationData(typeof(TView).Name);
            return new Uri("/" + NavigationResult.View + parser.FromData(NavigationResult));
        }

        public Uri UriFor<TView>(Action<NavigationData> parameterBuilder) where TView : IView
        {
            NavigationResult = new NavigationData(typeof(TView).Name);
            return new Uri("/" + NavigationResult.View + parser.FromData(NavigationResult));
        }
    }
}
